﻿using System;

namespace QstkCore.DataFrame
{
    public class IntRange
    {
        public IntRange(int min, int max)
        {
            Minimum = min;
            Maximum = max;
        }

        /// <summary>
        /// Minimum value of the range
        /// </summary>
        public int? Minimum { get; set; }

        /// <summary>
        /// Maximum value of the range
        /// </summary>
        public int? Maximum { get; set; }

        /// <summary>
        /// Presents the IntRange in readable format
        /// </summary>
        /// <returns>String representation of the IntRange</returns>
        public override string ToString() { return String.Format("[{0} - {1}]", Minimum, Maximum); }

        /// <summary>
        /// Determines if the range is valid
        /// </summary>
        /// <returns>True if range is valid, else false</returns>
        public Boolean IsValid()
        {
            return Minimum <= Maximum;
        }

        /// <summary>
        /// Determines if the provided value is inside the range
        /// </summary>
        /// <param name="value">The value to test</param>
        /// <returns>True if the value is inside IntRange, else false</returns>
        public Boolean ContainsValue(int? value)
        {
            return (Minimum <= value) && (value <= Maximum);
        }

        /// <summary>
        /// Determines if this IntRange is inside the bounds of another range
        /// </summary>
        /// <param name="intRange">The parent range to test on</param>
        /// <returns>True if range is inclusive, else false</returns>
        public Boolean IsInsideRange(IntRange intRange)
        {
            return this.IsValid() && intRange.IsValid() && intRange.ContainsValue(this.Minimum) && intRange.ContainsValue(this.Maximum);
        }

        /// <summary>
        /// Determines if another range is inside the bounds of this range
        /// </summary>
        /// <param name="intRange">The child range to test</param>
        /// <returns>True if range is inside, else false</returns>
        public Boolean ContainsRange(IntRange intRange)
        {
            return this.IsValid() && intRange.IsValid() && this.ContainsValue(intRange.Minimum) && this.ContainsValue(intRange.Maximum);
        }
    }
}
